
package com.zsrt.jmj.children.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.zsrt.jmj.children.dao.ChildrenDao;
import com.zsrt.jmj.children.entity.ChildrenEntity;
import com.zsrt.jmj.utils.DBUtil;

public class ChildrenDaoImpl implements ChildrenDao {

	@Override
	public List<ChildrenEntity> findAllPositions() throws Exception {
		
		List<ChildrenEntity> list  =new ArrayList<>();
		
		Connection connection = DBUtil.getConnect();
		String sql = "SELECT * from jmj_children_t WHERE FATHER_ID=2001";
		PreparedStatement ps = connection.prepareStatement(sql );

		ResultSet query = ps.executeQuery();
		while (query.next()) {
			ChildrenEntity entity = new ChildrenEntity();
			
			entity.setId(query.getInt(1));
			entity.setChildrenName(query.getString(2));
			entity.setFatherId(query.getInt(3));
			list.add(entity);
		}
		DBUtil.closeResources(query, ps, connection);
		return list;
	}

	@Override
	public List<ChildrenEntity> findAllEducations() throws Exception {
		List<ChildrenEntity> list  =new ArrayList<>();
		
		Connection connection = DBUtil.getConnect();
		String sql = "SELECT * from jmj_children_t WHERE FATHER_ID=1001";
		PreparedStatement ps = connection.prepareStatement(sql );

		ResultSet query = ps.executeQuery();
		while (query.next()) {
			ChildrenEntity entity = new ChildrenEntity();
			
			entity.setId(query.getInt(1));
			entity.setChildrenName(query.getString(2));
			entity.setFatherId(query.getInt(3));
			list.add(entity);
		}
		DBUtil.closeResources(query, ps, connection);
		return list;
	}

	@Override
	public List<ChildrenEntity> findAll(int fId) throws Exception {
		List<ChildrenEntity> list  =new ArrayList<>();
		
		Connection connection = DBUtil.getConnect();
		String sql = "SELECT * from jmj_children_t WHERE FATHER_ID=?";
		PreparedStatement ps = connection.prepareStatement(sql );
		ps.setInt(1, fId);
		ResultSet query = ps.executeQuery();
		while (query.next()) {
			ChildrenEntity entity = new ChildrenEntity();
			
			entity.setId(query.getInt(1));
			entity.setChildrenName(query.getString(2));
			entity.setFatherId(query.getInt(3));
			list.add(entity);
		}
		DBUtil.closeResources(query, ps, connection);
		return list;
	}

}
